package com.jjiang.bbmall.order.vo;

import lombok.Data;
import lombok.Getter;
import lombok.Setter;

import java.math.BigDecimal;
import java.util.List;
import java.util.Map;

// 订单确认页需要用的数据
public class OrderConfirmVo {

    // 收获地址
    @Getter
    @Setter
    private List<MemberReceiveAddressVo> address;

    // 当前选中的购物项
    @Getter
    @Setter
    private List<OrderItemVo> items;

    // 发票记录...

    // 优惠信息
    @Getter
    @Setter
    private Integer integration;

    public Integer getCount() {
        Integer count = 0;
        for (OrderItemVo item : items) {
            count += item.getCount();
        }
        return count;
    }

    // 订单总额
    public BigDecimal getTotal() {
        BigDecimal innerTotal = new BigDecimal("0");
        if (items != null) {
            for (OrderItemVo item : items) {
                innerTotal = innerTotal.add(item.getTotalPrice());
            }
        }
        return innerTotal;
    }

    // 应付总额
    public BigDecimal getPayPrice() {
        BigDecimal innerTotal = new BigDecimal("0");
        if (items != null) {
            for (OrderItemVo item : items) {
                innerTotal = innerTotal.add(item.getTotalPrice());
            }
        }
        return innerTotal;
    }

    // 订单防重令牌
    @Getter
    @Setter
    private String orderToken;

    @Getter
    @Setter
    private Map<Long, Boolean> stocks;
}
